/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int aviaries = 0;
    int guinea_pigs = 0;
    int used = 0;
    for (int i = 0; i < n; i++) {
      int day;
      cin >> day;
      if (day == 1) {
        guinea_pigs++;
        used++;
      } else {
        used = (guinea_pigs + 1) / 2;
        if (guinea_pigs != 0 && guinea_pigs % 2 == 0) {
          ++used;
        }
      }
      aviaries = std::max(aviaries, used);
    }
    cout << aviaries << '\n';
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("B. Settlement of Guinea Pigs.in", "r", stdin);
  freopen("B. Settlement of Guinea Pigs.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
